#!/opt/homebrew/bin/python3.9

#import Pillow






from PIL import Image,ImageDraw,ImageGrab;

from PIL import ImageFilter,ImageFont,ImageColor, ImageDraw;


# example 1
im = Image.open("./data/短图1.jpg");
print(im.mode)
print(im.size)
#im.show()
im_gray = im.convert('L')
print(im.mode)
im_gray.save("./data/短图grap.jpg")
#im_gray.show()

# example 2
r,g,b = im.split()
g.save(r'./data/gree.jpg')
#g.show()
img_bgr = Image.merge("RGB", (b,g,r))
img_bgr.save("./data/BGR.jpg")
#img_bgr.show()

# example 3

im_30 = im.rotate(30)
print(im_30.size)
#im_30.show()
im_30.save("./data/im_30.jpg")

im_30_x = im.rotate(30, expand=True)
im_30_x.save("./data/im_30_x.jpg")
#im_30_x.show()

im_crop = im.crop((400,400,600,800))
#im_crop.show()
im_crop.save("./data/im_crop_x.jpg")


im_copy = im.copy()
im2 = im
im2.paste(im_copy, (400,225))
im2.save("./data/im_copy_x.jpg")
#im.show()


im = Image.open("./data/短图1.jpg");
im_detail = im.filter(ImageFilter.DETAIL)
im_detail.save(r'./data/DETAIL.jpg')
#im_detail.show()

im_blur = im.filter(ImageFilter.BLUR)
im_blur.save(r'./data/BLUR.jpg')
#im_blur.show()

im_contour = im.filter(ImageFilter.CONTOUR)
im_contour.save(r'./data/CONTOUR.jpg')
#im_contour.show()

im_FIND_EDGES = im.filter(ImageFilter.FIND_EDGES)
im_FIND_EDGES.save(r'./data/FIND_EDGES.jpg')
#im_FIND_EDGES.show()

im = Image.new("RGB", (800,300), color=(32,64,128))
draw = ImageDraw.Draw(im)
draw.line((0,200,800,200), width=2, fill=(255,255,255))

#font = ImageFont.truetype("simfang.ttf", 32)
draw.text([130,230], "i use python", fill='white')
#im.show()

im = ImageGrab.grab((1200,600,1920,1080))
im.show()





